package Array;

import java.util.Scanner;

public class studentManage {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入班级学生总人数:");
        int number = scan.nextInt();
        int[] snos1 = new int[number];
        String[] snos2 = new String[number];
        int[] snos3 = new int[number];
        int[] snos4 = new int[number];

        for (int i = 0; i < snos1.length; i++) {
            System.out.print("请输入第" + (i + 1) + "个学生的学号");
            snos1[i] = scan.nextInt();
            System.out.print("请输入第" + (i + 1) + "个学生的姓名");
            snos2[i] = scan.next();
            System.out.print("请输入第" + (i + 1) + "个学生的语文成绩");
            snos3[i] = scan.nextInt();
            System.out.print("请输入第" + (i + 1) + "个学生的数学成绩");
            snos4[i] = scan.nextInt();
            System.out.print("已录入第" + (i + 1) + "个学生的信息\n");
        }
        System.out.println("---------------学生信息---------------");
        System.out.println("学号          姓名       语文成绩           数学成绩            总成绩");
        for (int i = 0; i < snos1.length; i++) {
            System.out.println(snos1[i] + "   " + snos2[i] + "   " + snos3[i] + "    " + snos4[i] + "    " + (snos3[i] + snos4[i]));
        }

        int chineseMax = 0;
        int chineseMin = 0;
        int mathMax = 0;
        int mathMin = 0;
        for (int i = 0; i < snos1.length; i++) {
            if (snos3[i] > snos3[chineseMax]) {
                chineseMax = i;
            }
            if (snos3[i] < snos3[chineseMin]) {
                chineseMin = i;
            }
            if (snos4[i] > snos3[chineseMax]) {
                mathMax = i;
            }
            if (snos4[i] < snos3[chineseMin]) {
                mathMin = i;
            }
        }
        System.out.println("----------语文最高和最低成绩-------------");
        System.out.println("语文成绩最高的学生信息：");
        System.out.println(snos1[chineseMax] + "   " + snos2[chineseMax] + "   " + snos3[chineseMax] + "    " + snos4[chineseMax] + "    " + (snos3[chineseMax] + snos4[chineseMax]));
        System.out.println("语文成绩最低的学生信息：");
        System.out.println(snos1[chineseMin] + "   " + snos2[chineseMin] + "   " + snos3[chineseMin] + "    " + snos4[chineseMin] + "    " + (snos3[chineseMin] + snos4[chineseMin]));
        System.out.println("----------数学最高和最低成绩-------------");
        System.out.println("数学成绩最高的学生信息：");
        System.out.println(snos1[mathMax] + "   " + snos2[mathMax] + "   " + snos3[mathMax] + "    " + snos4[mathMax] + "    " + (snos3[mathMax] + snos4[mathMax]));
        System.out.println("语文成绩最低的学生信息：");
        System.out.println(snos1[mathMin] + "   " + snos2[mathMin] + "   " + snos3[mathMin] + "    " + snos4[mathMin] + "    " + (snos3[mathMin] + snos4[mathMin]));
        System.out.println("-------------全班语文成绩和数学成绩的平均分---------------");
        int sum_chinese = 0;
        int sum_math = 0;
        for (int i = 0; i < snos1.length; i++) {
            sum_chinese += snos3[i];
            sum_math += snos4[i];
        }

        System.out.println("全班语文成绩的平均分：" + (sum_chinese / snos1.length));
        System.out.println("全班数学成绩的平均分：" + (sum_math / snos1.length));


        int[] total = new int[number];
        for (int i = 0; i < total.length; i++) {
            total[i] = snos3[i] + snos4[i];
        }
        int[] arr = {13, 42, 12, 3, 50};
        for (int i = 0; i < snos1.length - 1; i++) {
            for (int j = 0; j < snos1.length - i - 1; j++) {
                if (total[j] < total[j+1]) {
                    int temp = total[j];
                    total[j] = total[j+1];
                    total[j+1] = temp;

                    temp = snos1[j];
                    snos1[j] = snos1[j+1];
                    snos1[j+1] = temp;

                    String tempStr = snos2[j];
                    snos2[j] = snos2[j+1];
                    snos2[j+1] = tempStr;

                    temp = snos3[j];
                    snos3[j] = snos3[j+1];
                    snos3[j+1] = temp;
                    temp = snos4[j];
                    snos4[j] = snos4[j+1];
                    snos4[j+1] = temp;
                }
            }
        }
        System.out.println("-----------班级排名---------------");
        System.out.println("名次          学号          姓名       语文成绩           数学成绩            总成绩");
        for (int i = 0; i < snos1.length; i++) {
            System.out.println((i + 1) + "     " + snos1[i] + "   " + snos2[i] + "   " + snos3[i] + "    " + snos4[i] + "    " + total[i]);

        }
        System.out.println("-----------根据学号查询学生信息-------------");
        System.out.println("请输入要查询的学生学号：");
        int put = scan.nextInt();
        int index = -1;
        for (int i = 0; i < snos1.length; i++) {
            if(put == snos1[i]){
                index = i;
                break;
            }
        }
        if (index!=-1){
            System.out.println("------------------查询结果----------------------");
            System.out.println("学号          姓名       语文成绩           数学成绩            总成绩");
            System.out.println(snos1[index] + "   " + snos2[index] + "   " + snos3[index] + "    " + snos4[index] + "    " + total[index]);
        }else{
            System.out.println("没有找到学号为"+put+"的学生信息");
        }
    }
}
